import type { User } from '@/types/user'
import { request } from '@/utils/request'

// 注册
export const register = (username: string, password: string) => {
  const data = new URLSearchParams()
  data.append('username', username)
  data.append('password', password)
  return request('/user/register', 'POST', data)
}

// 登录
export const login = (username: string, password: string) => {
  const data = new URLSearchParams()
  data.append('username', username)
  data.append('password', password)
  return request<string>('/user/login', 'POST', data)
}

export const getUserInfo = () => request<User>('/user/userInfo')

export const updateUserInfo = (user: User) =>
  request('/user/update', 'PUT', user)

export const updateAvatar = (avatarUrl: string) =>
  request(`/user/updateAvatar?avatarUrl=${avatarUrl}`, 'PATCH')
// export const updateAvatar = (avatarUrl: string) =>
//   request(`/user/updateAvatar`, 'PATCH', { avatarUrl })
